package com.chen.pfm.utils;

import com.chen.pfm.AAChartCoreLib.AAChartCreator.AAChartModel;
import com.chen.pfm.AAChartCoreLib.AAChartCreator.AAChartView;
import com.chen.pfm.AAChartCoreLib.AAChartCreator.AASeriesElement;
import com.chen.pfm.AAChartCoreLib.AAChartEnum.AAChartAnimationType;
import com.chen.pfm.AAChartCoreLib.AAChartEnum.AAChartSymbolStyleType;
import com.chen.pfm.AAChartCoreLib.AAChartEnum.AAChartType;
import com.chen.pfm.AAChartCoreLib.AAOptionsModel.AADataLabels;
import com.chen.pfm.AAChartCoreLib.AAOptionsModel.AAPie;
import com.chen.pfm.AAChartCoreLib.AAOptionsModel.AAStyle;
import ohos.aafwk.content.Intent;

import java.util.HashMap;

public class AAChartUtil {

private String[] colors={"#c38783","#000000","#4dac94","#1afa29","#f7f728",
        "#b71c1c","#0daf1e","#0d6b16","#25e3e7","#1fb1b5","#16517b","#1f1fcd",
        "#0c9674", "#7dffc0", "#d11b5f", "#8a35b9", "#b91a90", "#EA007B","#ff383b",
        "#b96d87","#FF3D8C0B","#820f37"};

  public static  AAChartModel configurePieChart(String title, String subtitle,String commonDescription,Object[][] data) {
      AAStyle aaStyle=new AAStyle();
      aaStyle.fontSize(13f);

      AAChartModel series = new AAChartModel()
              .chartType(AAChartType.Pie)
              .backgroundColor("#ffffff")
              .title(title)//标题
              .colorsTheme(new String[]{
                      "#c38783","#000000","#4dac94",
                      "#1afa29","#f7f728", "#b71c1c",
                      "#bfbfbf","#0d6b16","#25e3e7",
                      "#1fb1b5","#16517b","#1f1fcd",
                      "#707070", "#7dffc0", "#1296db",
                      "#8a35b9", "#cdc52a", "#820f37",
                      "#ff383b", "#b96d87","#d81e06",
                      "b91a90","#EA007B","#eea3f2"
              })
              .titleStyle(aaStyle)
              .subtitle(subtitle)//副标题
              .dataLabelsEnabled(true)//是否直接显示扇形图数据
              .series(new AAPie[]{
                              new AAPie()
                                      .name(commonDescription)//描述详细数据，展示是占的比例
                                      .innerSize("20%")
                                      .size(150f)
                                      .dataLabels(new AADataLabels()
                                              .enabled(true)
                                              .useHTML(true)
                                              .distance(5f)
                                              .format("<b>{point.name}</b>: <br> {point.percentage:.2f} %"))
                                      .data(data)
                              ,
                      }
              );

      return series;
  }
    public static AAChartModel configureAAChartColumnModel(String title, String subtitle,String[] categories ,Object[] income,Object[] expenditure,Object[] property,Object[] surplus) {
        AAStyle aaStyle=new AAStyle();
        aaStyle.fontSize(13f);
        AASeriesElement element1 = new AASeriesElement()
                .name("收入")
                .data(income);
        AASeriesElement element2 = new AASeriesElement()
                .name("支出")
                .data(expenditure);
        AASeriesElement element3 = new AASeriesElement()
                .name("资产")
                .data(property);
        AASeriesElement element4 = new AASeriesElement()
                .name("结余")
                .data(surplus);
        //配置相同属性
        AAChartModel aaChartModel = new AAChartModel()
                .chartType(AAChartType.Column)
                .title(title)
                .titleStyle(aaStyle)
                .subtitle(subtitle)
                .backgroundColor("#ffffff")
                .dataLabelsEnabled(false)
                .yAxisGridLineWidth(0f)
                .yAxisTitle("账单金额")
                .touchEventEnabled(true)
                .series(new AASeriesElement[]{element1, element2, element3, element4});
            aaChartModel
                    //测试的假数据，位于x轴处的字段
//                    .categories(new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"})
                    .categories(categories)
                    .legendEnabled(true)
                    //每个柱子的颜色划分
                    .colorsTheme(new String[]{"#4dac94", "#d81e06", "#1296db", "#4ce0c7"})
                    .animationType(AAChartAnimationType.EaseOutCubic)
                    .animationDuration(1200);

        return aaChartModel;
    }
    public static  AAChartModel configureAAChartLineModel(String title, String subtitle,String[] categories ,Object[] income,Object[] expenditure,Object[] property,Object[] surplus) {
        AAStyle aaStyle=new AAStyle();
        aaStyle.fontSize(13f);
      AASeriesElement element1 = new AASeriesElement()
                .name("收入")
                .data(income);
        AASeriesElement element2 = new AASeriesElement()
                .name("支出")
                .data(expenditure);
        AASeriesElement element3 = new AASeriesElement()
                .name("资产")
                .data(property);
        AASeriesElement element4 = new AASeriesElement()
                .name("结余")
                .data(surplus);

        //配置相同属性
        AAChartModel aaChartModel = new AAChartModel()
                .chartType(AAChartType.Line)
                .title(title)
                .titleStyle(aaStyle)
                .subtitle(subtitle)
                .backgroundColor("#ffffff")
                .dataLabelsEnabled(false)
                .yAxisTitle("账单金额")
                .yAxisGridLineWidth(0f)
                .touchEventEnabled(true)
                .series(new AASeriesElement[]{element1, element2, element3, element4});
        //配置不同属性
            aaChartModel
                    //测试的假数据，位于x轴处的字段
                    .categories(categories)
                    .legendEnabled(true)
                    //每个柱子的颜色划分
                    .colorsTheme(new String[]{"#4dac94", "#d81e06", "#1296db", "#4ce0c7"})
                    .animationType(AAChartAnimationType.EaseOutCubic)
                    .animationDuration(1200)
                    .markerSymbolStyle(AAChartSymbolStyleType.BorderBlank)//设置折线连接点样式为:边缘白色
                    .markerRadius(6f);

        return aaChartModel;
    }


}
